"""
翻译服务：
1.创建chain prompt、llm、parser
2.创建FastAPi的应用app
3.创建一个路由   app,chain path
4.uvicorn启动app
"""
from fastapi import FastAPI
from model_utils import getLLM
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langserve import add_routes

_llm = getLLM()

_template = ChatPromptTemplate([("system","将以下内容翻译成{language}"),("human","{content}")])

_parser = StrOutputParser()

_chain = _template | _llm | _parser

app = FastAPI(
    title="翻译",
    version="1.0"
)

add_routes(
    app,
    _chain,
    path="/translate"
)

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app,host="0.0.0.0",port=50001)
